package com.hcs.chenyu;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.Map;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button mbtn_login,mbtn2_login,mbtn3_login;
    private EditText editText1,editText2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
    }
    private void initview() {
        mbtn_login = findViewById(R.id.btn_login);
        mbtn2_login = findViewById(R.id.btn2_login);
        mbtn3_login = findViewById(R.id.btn3_login);
        editText1 =findViewById(R.id.et_name);
        editText2 =findViewById(R.id.et_password);
        mbtn_login.setOnClickListener( this);
        mbtn2_login.setOnClickListener(this);
        mbtn3_login.setOnClickListener(this);



    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login: {
                Intent intent = new Intent(this, registermain.class);
                startActivity(intent);
                break;
            }
            case R.id.btn2_login: {
                AlertDialog dialog;
                AlertDialog.Builder builder = new AlertDialog.Builder(this)
                        .setTitle("请确认您的操作").setIcon(null)
                        .setMessage("是否退出此应用")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }

                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                dialog = builder.create();
                dialog.show();
                break;
            }
            case R.id.btn3_login: {
                Map<String, String> userInfo = administrationDatabase.getUserInfo(MainActivity.this);
                if (userInfo != null) {

                    if (editText1.getText().toString().equals(userInfo.get("ACCOUNT"))&& editText2.getText().toString().equals(userInfo.get("PASSWORD"))){
                        Intent intent1 = new Intent(MainActivity.this, loadingmain.class);
                        startActivity(intent1);
                    }


                }
            }

        }
    }
    }
